// UDPnet.h: interface for the CUDPnet class.
//
//////////////////////////////////////////////////////////////////////

#ifndef UDPNET_H
#define UDPNET_H

#include "oslayer/compile_opt.h"

#define MAXNETSVRTCPBUFSIZE 10240
#define MAXNETSVRBUFSIZE 10240



class CXThread
{
public:
	CXThread();
	~CXThread();
	bool XSingelCreateThread(void * func,void * para);
	bool XCreateThread(void * func,void * para);
	bool XTerminateThread();
protected:
	HANDLE hThread;
	
};

class CUDPNetDataAgent
{
public:
	CUDPNetDataAgent(){};
	virtual ~CUDPNetDataAgent(){};
	virtual void onUDPnetDataRecieve(unsigned char * data_buf,long data_size) = 0;
};

class CUDPnetSever
{
public:
	CUDPnetSever();
	virtual ~CUDPnetSever();
	bool StartSever(int svr_port);
	void SetNetDataAgent(CUDPNetDataAgent * nda);
	bool InitNet();
	struct in_addr clnaddr;
	protected:
	void OnDataRecv();
	CUDPNetDataAgent * net_data_agent;
	int port;
	unsigned char data_buf[MAXNETSVRBUFSIZE];
	long data_size;	
	friend XSTDCALL NetSeverThread(void * para);
	char run_state;
	socklen_t close_target_socket;
	CXThread  thread_net_svr;
};



class CUDPnetClient
{
public:
	CUDPnetClient();
	virtual ~CUDPnetClient();
	virtual bool OnSendData(void * data,int size);
	virtual bool LinkSvr(char * ip,int Port);
protected:
	int RunSocket;
	bool InitNet();
	struct sockaddr_in pin;
	int svlen;
};



#endif // !defined(AFX_UDPNET_H__3FC08C7A_2416_4304_885C_07B5F56FF321__INCLUDED_)
